#include <bits/stdc++.h>

using namespace std;

class Solution
{
public:
    int giveGem(vector<int> &gem, vector<vector<int>> &operations)
    {
        for (auto &operation : operations)
        {
            int give = operation[0], get = operation[1];
            int num = gem[give] / 2;
            gem[get] += gem[give] / 2;
            gem[give] -= num;
        }
        int max_ = INT_MIN;
        int min_ = INT_MAX;

        for (auto &e : gem)
        {
            max_ = max(max_, e);
            min_ = min(min_, e);
        }
        return max_ - min_;
    }
};